//
//  OrderPaperBoardViewController.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/24.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrderPaperBoardViewController.h"
#import "TitleInformationViewCell.h"
#import "WebViewController.h"
#import "InformationViewCell.h"
#import "SelectParameterViewCell.h"
#import "PaperBoardInformationCell.h"
#import "NoticeViewCell.h"
#import "FPButtonViewCell.h"
#import "KDCycleBannerView.h"
#import "TypeSelectView.h"
#import "PaperBoardDetialModel.h"
#import "OrderDetialViewController.h"
#import "LineTypeModel.h"
#import "BoxTypeModel.h"
#import "LengTypeModel.h"
#import "OrderDetialViewController.h"

@interface OrderPaperBoardViewController ()<UITableViewDelegate,UITableViewDataSource,KDCycleBannerViewDataSource,KDCycleBannerViewDelegate,UITextFieldDelegate>

@property (nonatomic, strong) BaseTableView         *tableView;
@property (nonatomic, strong) KDCycleBannerView     *cycleBannerViewBottom;
@property (nonatomic, strong) PaperBoardDetialModel *model;
@property (nonatomic, strong) UIView                *baseview;
@property (nonatomic, strong) NSArray               *cycleBannerArray;
@property (nonatomic, strong) UILabel               *boxtype;
@property (nonatomic, strong) UILabel               *linetype;
@property (nonatomic, strong) UILabel               *lentype;
@property (nonatomic, strong) UILabel               *paperboardnum;
@property (nonatomic, strong) UITextField           *height;
@property (nonatomic, strong) UITextField           *width;
@property (nonatomic, strong) UITextField           *boxnum;
@property (nonatomic, strong) NSString              *tempBoxNum;
@property (nonatomic, strong) NSString              *tempHeight;
@property (nonatomic, strong) NSString              *tempWidth;
@property (nonatomic, strong) TypeSelectView        *LineTypeView;
@property (nonatomic, strong) TypeSelectView        *BoxTypeView;
@property (nonatomic, strong) TypeSelectView        *LengTypeView;
@property (nonatomic, strong) NSMutableArray        *LineType;
@property (nonatomic, strong) NSMutableArray        *BoxType;
@property (nonatomic, strong) NSMutableArray        *LengType;
@property (nonatomic, assign) NSInteger             selectType;
@property (nonatomic, strong) NSMutableString       *lengId;
@property (nonatomic, strong) NSMutableString       *boxId;
@property (nonatomic, strong) NSMutableString       *lineId;
@property (nonatomic, strong) NSMutableString       *price;
@property (nonatomic, strong) NSMutableString       *totalPrice;
@end

@implementation OrderPaperBoardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self setNavBar];
    [self setTableView];
    [self getData];
    [self getLineType];
    [self getBoxtype];
    [self getLengType];
    [self setfooter];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(transformView:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.
}

- (void)setNavBar {
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 14, 44)];
    [backBtn setImage:[UIImage imageNamed:@"返回白色"] forState:UIControlStateNormal];
    backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
    [backBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
    [self setTitle:@"纸板订购"];
}

-(void)setBoxTypeView{
    self.BoxTypeView = [[TypeSelectView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    NSMutableArray *noteArr = [NSMutableArray array];
    for(int i = 0;i < self.BoxType.count;i++){
        BoxTypeModel *model = [[BoxTypeModel alloc] init];
        model = [_BoxType objectAtIndex:i];
        [noteArr addObject:model.box_type];
    }
    [self.BoxTypeView modelArrayForView:noteArr andSelect:_selectType];
    __weak __typeof(self) weakSelf = self;
    self.BoxTypeView.hiddenClick = ^{
        [weakSelf hiddenBoxTypView];
    };
    
    self.BoxTypeView.doneClick = ^(NSInteger selectIndex){
        weakSelf.selectType = selectIndex;
        BoxTypeModel *model = [[BoxTypeModel alloc] init];
        model = [weakSelf.BoxType objectAtIndex:selectIndex];
        weakSelf.boxtype.text = model.box_type;
        weakSelf.boxId = [model.box_id copy];
        [weakSelf hiddenBoxTypView];
    };
    [kKeyWindow addSubview:self.BoxTypeView];
}

- (void)hiddenBoxTypView{
    self.BoxTypeView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.BoxTypeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

-(void)setLineTypeView{
    self.LineTypeView = [[TypeSelectView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    NSMutableArray *noteArr = [NSMutableArray array];
    for(int i = 0;i < self.LineType.count;i++){
        LineTypeModel *model = [[LineTypeModel alloc] init];
        model = [_LineType objectAtIndex:i];
        [noteArr addObject:model.line_type];
    }
    [self.LineTypeView modelArrayForView:noteArr andSelect:_selectType];
    __weak __typeof(self) weakSelf = self;
    self.LineTypeView.hiddenClick = ^{
        [weakSelf hiddenLineTypView];
    };
    
    self.LineTypeView.doneClick = ^(NSInteger selectIndex){
        weakSelf.selectType = selectIndex;
        LineTypeModel *model = [[LineTypeModel alloc] init];
        model = [weakSelf.LineType objectAtIndex:selectIndex];
        weakSelf.linetype.text = model.line_type;
        weakSelf.lineId = [model.line_id copy];
        [weakSelf hiddenLineTypView];
    };
    [kKeyWindow addSubview:self.LineTypeView];
}

- (void)hiddenLineTypView{
    self.LineTypeView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.LineTypeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

-(void)setLengTypeView{
    self.LengTypeView = [[TypeSelectView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    NSMutableArray *noteArr = [NSMutableArray array];
    for(int i = 0;i < self.LengType.count;i++){
        LengTypeModel *model = [[LengTypeModel alloc] init];
        model = [_LengType objectAtIndex:i];
        [noteArr addObject:model.leng_type];
    }
    [self.LengTypeView modelArrayForView:noteArr andSelect:_selectType];
    __weak __typeof(self) weakSelf = self;
    self.LengTypeView.hiddenClick = ^{
        [weakSelf hiddenLengTypView];
    };
    
    self.LengTypeView.doneClick = ^(NSInteger selectIndex){
        weakSelf.selectType = selectIndex;
        LengTypeModel *model = [[LengTypeModel alloc] init];
        model = [weakSelf.LengType objectAtIndex:selectIndex];
        weakSelf.lentype.text = model.leng_type;
        weakSelf.lengId = [model.leng_id copy];
        [weakSelf getPrice];
        [weakSelf hiddenLengTypView];
    };
    [kKeyWindow addSubview:self.LengTypeView];
}

- (void)hiddenLengTypView{
    self.LengTypeView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.LengTypeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

-(void)click{
    NSLog(@"clicked");
}

- (void)setTableView {
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(50) )];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

-(void)setfooter{
    FPBottomButtonView *footer = [FPBottomButtonView initBottomButtonViewWithTitle:@"立即购买"];
    footer.frame = CGRectMake(0,SCREEN_HEIGHT - ScreenX375(50) - NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, ScreenX375(50));
    footer.threeTextButton.hidden = YES;
    footer.threeButton.hidden = YES;
    footer.fourButton.hidden = YES;
    footer.sixButton.hidden = YES;
    footer.fiveClick = ^{
        __weak __typeof(self) weakSelf = self;
        
        [weakSelf.height resignFirstResponder];
        [weakSelf.height resignFirstResponder];
        [weakSelf.height resignFirstResponder];
        
        if(self.boxtype.text.length == 0){
            [HttpManager showNoteMsg:@"请选择箱型"];
        }else if (self.linetype.text.length == 0){
            [HttpManager showNoteMsg:@"请选择压线方式"];
        }else if (self.lentype.text.length == 0) {
            [HttpManager showNoteMsg:@"请选择楞型"];
        }else if (self.height.text.length == 0 || self.width.text.length == 0) {
            [HttpManager showNoteMsg:@"请输入完整的尺寸"];
        }else{
            OrderDetialViewController *vc = [[OrderDetialViewController alloc] init];
            vc.isPaperBoard = YES;
            vc.goods_id = self.productId;
            vc.goods_nums = self.boxnum.text;
            vc.total_price = self.totalPrice;
            [self.navigationController pushViewController:vc animated:YES];
        }
    };
    [self.view addSubview:footer];
}

#pragma tableview

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 3;
    }else if (section == 1){
        return 6;
    }else{
        return 4;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *title1 = [[NSArray alloc] initWithObjects:@"选择箱型 :",@"压线方式 :", @"楞       型 :", @"纸箱规格 :", @"纸箱数量 :", @"纸板数量 :",  nil];
    NSArray *title2 = [[NSArray alloc] initWithObjects:@"纸板价格 :",@"纸板单价 :", @"纸板库存 :",  nil];
    NSArray *price = [[NSArray alloc] initWithObjects:@"0.00元(0.00m²)",@"0.00元/m²", @"0.00m²", nil];
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"bannerCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                self.cycleBannerViewBottom = [KDCycleBannerView new];
                self.cycleBannerViewBottom.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(190)); //位置及宽高
                self.cycleBannerViewBottom.datasource = self;
                self.cycleBannerViewBottom.delegate = self;
                self.cycleBannerViewBottom.continuous = YES; //是否连续显示
                self.cycleBannerViewBottom.autoPlayTimeInterval = 4; //时间间隔
                [cell addSubview:self.cycleBannerViewBottom];
            }
            return cell;
        }else if (indexPath.row == 1){
            TitleInformationViewCell *cell = [TitleInformationViewCell cellWithTableView:tableView andIndexPath:indexPath];
            if (_model) {
                [cell initWithModel:_model];
            }
            return cell;
        }else{
            InformationViewCell *cell = [InformationViewCell cellWithTableView:tableView andIndexPath:indexPath];
            if (_model) {
                [cell initWithModel:_model];
            }
            return cell;
        }
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(17), ScreenX375(7), ScreenX375(12))];
            [selectBtn setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
            [cell addSubview:selectBtn];
            
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), ScreenX375(349), ScreenX375(1))];
            UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
            [line setBackgroundColor:color];
            [cell addSubview:line];
            
            _boxtype = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(15), ScreenX375(200), ScreenX375(14))];
            _boxtype.font = Kfont(14);
            _boxtype.textColor = REXADECIMALCOLOR(@"#333333");
            _boxtype.textAlignment = NSTextAlignmentLeft;
            [cell addSubview:_boxtype];
            
            return cell;
        }else if(indexPath.row == 1){
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(17), ScreenX375(7), ScreenX375(12))];
            [selectBtn setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
            [cell addSubview:selectBtn];
            
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), ScreenX375(349), ScreenX375(1))];
            UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
            [line setBackgroundColor:color];
            [cell addSubview:line];
            
            _linetype = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(15), ScreenX375(200), ScreenX375(14))];
            _linetype.font = Kfont(14);
            _linetype.textColor = REXADECIMALCOLOR(@"#333333");
            _linetype.textAlignment = NSTextAlignmentLeft;
            [cell addSubview:_linetype];
            
            return cell;
        }else if (indexPath.row == 2){
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(17), ScreenX375(7), ScreenX375(12))];
            [selectBtn setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
            [cell addSubview:selectBtn];
            
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), ScreenX375(349), ScreenX375(1))];
            UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
            [line setBackgroundColor:color];
            [cell addSubview:line];
            
            _lentype = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(15), ScreenX375(200), ScreenX375(14))];
            _lentype.font = Kfont(14);
            _lentype.textColor = REXADECIMALCOLOR(@"#333333");
            _lentype.textAlignment = NSTextAlignmentLeft;
            [cell addSubview:_lentype];
            
            return cell;
        }else if (indexPath.row == 3){
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
            UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
            NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
            [bar setItems:buttonsArray];
            
            _height = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(111), ScreenX375(8), ScreenX375(83), ScreenX375(30))];
            _height.layer.borderWidth = 0.5;
            _height.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
            _height.layer.cornerRadius = 15.0;
            _height.delegate = self;
            _height.keyboardType = UIKeyboardTypeNumberPad;
            _height.textAlignment = NSTextAlignmentCenter;
            _height.inputAccessoryView = bar;
            [cell addSubview:_height];
            
            _width = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(214), ScreenX375(8), ScreenX375(83), ScreenX375(30))];
            _width.layer.borderWidth = 0.5;
            _width.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
            _width.layer.cornerRadius = 15.0;
            _width.delegate = self;
            _width.keyboardType = UIKeyboardTypeNumberPad;
            _width.textAlignment = NSTextAlignmentCenter;
            _width.inputAccessoryView = bar;
            [cell addSubview:_width];
            
            
            UIImageView *multip =[[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(199), ScreenX375(17), ScreenX375(10), ScreenX375(10))];
            multip.image = [UIImage imageNamed:@"×"];
            [cell addSubview:multip];
            
            UILabel *unit =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(302), ScreenX375(17), ScreenX375(60), ScreenX375(12))];
            unit.text = @"cm( 门幅 )";
            unit.font = Kfont(12);
            unit.textColor = REXADECIMALCOLOR(@"#333333");
            unit.textAlignment = NSTextAlignmentLeft;
            [cell addSubview:unit];
            
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(44), ScreenX375(349), ScreenX375(1))];
            UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
            [line setBackgroundColor:color];
            [cell addSubview:line];
            
            return cell;
        }else if (indexPath.row == 4){
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            if (_baseview == nil) {
                _baseview =[[UIView alloc] initWithFrame:CGRectMake(ScreenX375(87), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
                _baseview.layer.cornerRadius = 15.0;
                _baseview.layer.borderWidth = 0.6;
                _baseview.layer.borderColor = ThemeColor.CGColor;
                _baseview.clipsToBounds = YES;
                
                UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                [bar setItems:buttonsArray];
                
                _boxnum =[[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(35), ScreenX375(0), ScreenX375(39), ScreenX375(30))];
                _boxnum.text = @"1";
                _boxnum.tag = 100;
                _boxnum.font = Kfont(13);
                _boxnum.layer.borderColor = ThemeColor.CGColor;
                _boxnum.layer.borderWidth = 0.6;
                _boxnum.inputAccessoryView = bar;
                _boxnum.delegate = self;
                _boxnum.keyboardType = UIKeyboardTypeNumberPad;
                _boxnum.textColor = REXADECIMALCOLOR(@"#333333");
                _boxnum.textAlignment = NSTextAlignmentCenter;
                
                [_boxnum addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionInitial context:nil];
                [_baseview addSubview:_boxnum];
                
                UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                leftbutton.tag = 101;
                [leftbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [leftbutton setImage:[UIImage imageNamed:@"_"] forState:UIControlStateNormal];
                [leftbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseview addSubview:leftbutton];
                
                UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(74), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                rightbutton.tag = 102;
                [rightbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                [rightbutton setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
                [rightbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                [_baseview addSubview:rightbutton];
                
                [cell addSubview:_baseview];
            }
            
            
            return cell;
        }else{
            SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            [cell setTitletext:[title1 objectAtIndex:indexPath.row]];
            
            _paperboardnum =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(87), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
            _paperboardnum.text = @"1片";
            _paperboardnum.font = Kfont(12);
            _paperboardnum.layer.cornerRadius = 15.0;
            _paperboardnum.layer.borderWidth = 1.0;
            _paperboardnum.textAlignment = NSTextAlignmentCenter;
            _paperboardnum.layer.borderColor = REXADECIMALCOLOR(@"#eeeeee").CGColor;
            _paperboardnum.clipsToBounds = YES;
            _paperboardnum.backgroundColor = REXADECIMALCOLOR(@"#eeeeee");
            _paperboardnum.textColor = REXADECIMALCOLOR(@"#999999");
            [cell addSubview:_paperboardnum];
            
            return cell;
        }
    } else {
        if (indexPath.row == 3) {
            NoticeViewCell *cell = [NoticeViewCell cellWithTableView:tableView andIndexPath:indexPath];
            return cell;
        }else{
            if (indexPath.row == 0) {
                PaperBoardInformationCell *cell = [PaperBoardInformationCell cellWithTableView:tableView andIndexPath:indexPath];
                [cell settitletext:[title2 objectAtIndex:indexPath.row]];
                if (_model) {
                    if (_totalPrice != nil && _price != nil) {
                        NSString *size = [NSString stringWithFormat:@"%.2f",[_height.text floatValue]*[_width.text floatValue]/10000*[_boxnum.text integerValue]] ;
                        NSString *result = [[NSString alloc] initWithFormat:@"%@元(%@m²)",_totalPrice,size];
                        [cell setpricetext:result];
                    }else{
                        [cell setpricetext:[price objectAtIndex:indexPath.row]];
                    }
                }
                return cell;
            }else if (indexPath.row == 1){
                PaperBoardInformationCell *cell = [PaperBoardInformationCell cellWithTableView:tableView andIndexPath:indexPath];
                [cell settitletext:[title2 objectAtIndex:indexPath.row]];
                if (_price != nil) {
                    [cell setpricetext:[NSString stringWithFormat:@"%@元",_price]];
                }else{
                    [cell setpricetext:[price objectAtIndex:indexPath.row]];
                }
                return cell;
            }else{
                PaperBoardInformationCell *cell = [PaperBoardInformationCell cellWithTableView:tableView andIndexPath:indexPath];
                [cell settitletext:[title2 objectAtIndex:indexPath.row]];
                if (_model) {
                    NSString *result = [[NSString alloc] initWithFormat:@"%@m²",_model.store];
                    [cell setpricetext:result];
                }else{
                    [cell setpricetext:[price objectAtIndex:indexPath.row]];
                }
                return cell;
            }
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return ScreenX375(190);
        }else if (indexPath.row == 1){
            return ScreenX375(72);
        }else{
            return ScreenX375(35);
        }
    }else if (indexPath.section == 1) {
        return ScreenX375(45);
    }else{
        if (indexPath.row == 3) {
            return ScreenX375(75);
        }else{
            return ScreenX375(50);
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 10;
    }
    else{
        return 0;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            [self.view endEditing:YES];
            [UIView animateWithDuration:0.3 animations:^{
                self.BoxTypeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.BoxTypeView.shadowBtn.alpha = 1;
            }];
        }else if (indexPath.row == 1) {
            [self.view endEditing:YES];
            [UIView animateWithDuration:0.3 animations:^{
                self.LineTypeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.LineTypeView.shadowBtn.alpha = 1;
            }];
        }else if (indexPath.row == 2){
            [self.view endEditing:YES];
            [UIView animateWithDuration:0.3 animations:^{
                self.LengTypeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.LengTypeView.shadowBtn.alpha = 1;
            }];
        }
    }
}

-(void)btnDidClick:(UIButton*)sender{
    if (sender.tag == 101) {
        UILabel *label= (UILabel *)[[sender superview]viewWithTag:100];
        NSString *num = [[NSString alloc] init];
        num = label.text;
        if ([label.text integerValue] == 0) {
            label.text = @"0";
        }else{
            label.text = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] - 1];
        }
        _paperboardnum.text = [NSString stringWithFormat:@"%@片",_boxnum.text];
    }else{
        UILabel *label= (UILabel *)[[sender superview]viewWithTag:100];
        NSString *num = [[NSString alloc] init];
        num = label.text;
        NSString *temp = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] + 1];
        NSString *total_size =[NSString stringWithFormat:@"%.2f",[_height.text floatValue] * [_width.text floatValue] * [temp integerValue]/10000];
        
        if ([total_size floatValue] > [_model.store floatValue]) {
            [HttpManager showNoteMsg:@"不能超过库存信息"];
            label.text = num;
        }else{
            label.text = temp;
        }
        _paperboardnum.text = [NSString stringWithFormat:@"%@片",_boxnum.text];
    }
    
}

-(void)initData{
    _LineType = [[NSMutableArray alloc] initWithCapacity:20];
    _BoxType = [[NSMutableArray alloc] initWithCapacity:20];
    _LengType = [[NSMutableArray alloc] initWithCapacity:20];
}

-(void)getData{
    NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:@{@"factory_id":kNSUDefaultReadKey(@"FactoryId"),@"id":_productId,}];
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/cardboard_detail",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error = nil;
            self->_model = [[PaperBoardDetialModel alloc] initWithDictionary:successResponse[@"data"] error:&error];
            self.cycleBannerArray = successResponse[@"data"][@"pics"];
            [self.tableView reloadData];
            [self.cycleBannerViewBottom reloadDataWithCompleteBlock:nil];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
        }];
}

-(void)getLineType{;
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/line_way",REQUESTHEADER] andParameter:nil success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error = nil;
            for(NSDictionary *dict in successResponse[@"data"]){
                LineTypeModel *model = [[LineTypeModel alloc] initWithDictionary:dict error:&error];
                [self.LineType addObject:model];
            }
            [self setLineTypeView];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getBoxtype {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/box_type",REQUESTHEADER] andParameter:nil success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error = nil;
            for(NSDictionary *dict in successResponse[@"data"]){
                BoxTypeModel *model = [[BoxTypeModel alloc] initWithDictionary:dict error:&error];
                model.box_id = dict[@"id"];
                [self.BoxType addObject:model];
            }
            [self setBoxTypeView];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getLengType{
    NSDictionary *parameter = @{@"goods_id":_productId};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/leng_type",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error = nil;
            for(NSDictionary *dict in successResponse[@"data"]){
                LengTypeModel *model = [[LengTypeModel alloc] initWithDictionary:dict error:&error];
                model.leng_id = dict[@"leng_id"];
                [self.LengType addObject:model];
            }
            [self setLengTypeView];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getPrice{
    if(self.lengId != nil && self.height.text != nil && self.width.text != nil){
        NSDictionary *parameter = @{@"goods_id":_productId,@"leng_id":_lengId,@"square":[NSString stringWithFormat:@"%f",[_height.text floatValue]*[_width.text floatValue] *[self.boxnum.text floatValue] / 10000.0f]};
        [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/cardboard_price",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
            NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
            if ([status isEqualToString:@"1"]) {
                self.totalPrice = successResponse[@"allPrice"];
                self.price = successResponse[@"price"];
                [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
                [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
            }else {
                [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
            }
        } andFailure:^(id failureResponse) {
            [HttpManager showFail];
        }];
    }
}

-(void)turnToOrder{
    if(_boxtype.text.length == 0){
        [HttpManager showNoteMsg:@"请选择楞型"];
        if (_lentype.text.length == 0) {
            [HttpManager showNoteMsg:@"请选择压线方式"];
            if (_linetype.text.length == 0) {
                [HttpManager showNoteMsg:@"请选择箱型"];
                if (_height.text.length == 0 || _width.text.length == 0) {
                    [HttpManager showNoteMsg:@"请输入完整的尺寸"];
                }else{
                    OrderDetialViewController *vc = [[OrderDetialViewController alloc] init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
        }
    }
}

#pragma mark 轮播图代理委托

-(NSArray *)numberOfKDCycleBannerView:(KDCycleBannerView *)bannerView{
    NSMutableArray *urlArray = [NSMutableArray array];
    for (int i = 0; i < _cycleBannerArray.count; i++) {
        NSString *url = [NSString stringWithFormat:@"%@",_cycleBannerArray[i][@"pic"]];
        [urlArray addObject:url];
    }
    return urlArray;
}

-(UIViewContentMode)contentModeForImageIndex:(NSUInteger)index{
    return UIViewContentModeScaleToFill;
}

- (void)cycleBannerView:(KDCycleBannerView *)bannerView didSelectedAtIndex:(NSUInteger)index{
    NSLog(@"点击了第%ld个",(long)index);
    if ([_cycleBannerArray[index][@"url"] length] > 0) {
        WebViewController *vc = [[WebViewController alloc] init];
        vc.url = _cycleBannerArray[index][@"url"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark TextField代理
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == _boxnum) {
        NSString *total_size = [NSString stringWithFormat:@"%.2f",[_height.text floatValue] * [_width.text floatValue] * [_boxnum.text integerValue]/10000];
        
        if ([total_size floatValue] > [_model.store floatValue]) {
            [HttpManager showNoteMsg:@"不能超过库存量"];
            _boxnum.text = _tempBoxNum;
        }else{
            _boxnum.text = textField.text;
        }
        [self getPrice];
        _paperboardnum.text = [NSString stringWithFormat:@"%@片",_boxnum.text];
    }else if(textField == _height){
        NSString *total_size = [NSString stringWithFormat:@"%.2f",[_height.text floatValue] * [_width.text floatValue] * [_boxnum.text integerValue]/10000];
        
        if ([total_size floatValue] > [_model.store floatValue]) {
            [HttpManager showNoteMsg:@"不能超过库存量"];
            _height.text = _tempHeight;
        }else{
            _height.text = textField.text;
        }
        [self getPrice];
    }else{
        NSString *total_size = [NSString stringWithFormat:@"%.2f",[_height.text floatValue] * [_width.text floatValue] * [_boxnum.text integerValue]/10000];
        
        if ([total_size floatValue] > [_model.store floatValue]) {
            [HttpManager showNoteMsg:@"不能超过库存量"];
            _width.text = _tempWidth;
        }else{
            _width.text = textField.text;
        }
        [self getPrice];
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField == _boxnum) {
        _tempBoxNum = textField.text;
    }else if(textField == _height){
        _tempHeight = textField.text;
    }else{
        _tempWidth = textField.text;
    }
}

-(void)resignKey{
    [_height resignFirstResponder];
    [_width resignFirstResponder];
    [_boxnum resignFirstResponder];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"text"] && object == _boxnum) {
        [self getPrice];
    }
}

//键盘回收
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    for(UIView *view in self.view.subviews)
    {
        [view resignFirstResponder];
    }
}

//移动UIView
-(void)transformView:(NSNotification *)aNSNotification
{
    //获取键盘弹出前的Rect
    NSValue *keyBoardBeginBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGRect beginRect=[keyBoardBeginBounds CGRectValue];
    
    //获取键盘弹出后的Rect
    NSValue *keyBoardEndBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect  endRect=[keyBoardEndBounds CGRectValue];
    
    //获取键盘位置变化前后纵坐标Y的变化值
    CGFloat deltaY=endRect.origin.y-beginRect.origin.y;
    
    //在0.25s内完成self.view的Frame的变化，等于是给self.view添加一个向上移动deltaY的动画
    [UIView animateWithDuration:0.25f animations:^{
        [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + deltaY, self.view.frame.size.width, self.view.frame.size.height)];
    }];
}

@end

